<template>
	<view>
		<uni-nav-bar dark title="发布动态" fixed :statusBar="true" left-icon="left" @clickLeft="onLeft">
			<block slot="right">
				<view class="city">
					<view @click="onCreated">
						发布
					</view>
				</view>
			</block>

		</uni-nav-bar>
		<view>
			<uni-easyinput class="uni-mt-5" :inputBorder="false" type="textarea" trim="all" v-model="baseFormDat.title"
				placeholder="请输入内容"></uni-easyinput>
			<view class="uni-mt-5">
				<uni-file-picker limit="6" @select="select"></uni-file-picker>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		uploadAvatar
	} from '@/api/basketballTeam/index.js'
	import {addDynamic} from '@/api/dynamic/index.js'
	import {imageUrl} from '@/config.js'
	export default {
		data() {
			return {
				baseFormDat: {
					title: ''
				},
				image: [],
				imageUrl: imageUrl
			}
		},
		methods: {
			onLeft() {
				uni.navigateBack()
			},
			onCreated() {
				if (!this.baseFormDat.title) {
					this.$modal.msg('请输入内容')
					return
				}
				let contestId = uni.getStorageSync('contestId');
				if (this.image.length) {
					this.baseFormDat.img = this.image.join(',')
				}
				addDynamic({...this.baseFormDat,contestId}).then(res => {
					this.$modal.msg(res.msg)
					setTimeout(() => {
						uni.navigateBack()
					}, 600)
				})
			},
			select(e) {
				console.log('选择文件：', e)
				uploadAvatar({
					file: e.tempFiles[0].file
				}).then(res => {
					this.image.push(res.data);
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.uni-mt-5 {
		padding: 30rpx 20rpx;
	}
</style>